package code._15network.tcp.v3;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server  {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //创建server Socket
        ServerSocket serverSocket = new ServerSocket(9999);
        //连接、accept、得到socket
        Socket socket = serverSocket.accept();
        //获取socket输入流InputStream
        InputStream inputStream = socket.getInputStream();
        //创建反序列化流ObjectInputStrea、并进行包装
        ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
        //读取msg
        Student[] students=(Student[]) objectInputStream.readObject();
        //打印
        for (Student student : students) {
            System.out.println("student = " + student);
        }
        //释放资源
        objectInputStream.close();
        serverSocket.close();
        socket.close();
    }
}
